package com.lighthouse.note.base.service.impl;

import com.lighthouse.note.base.dao.KnowledgeNoteRepository;
import com.lighthouse.note.base.domain.KnowledgeNote;
import com.lighthouse.note.base.mapper.KnowledgeNoteMapper;
import com.lighthouse.note.base.service.IKnowledgeNoteService;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 小记Service业务层处理
 * 
 * @author ysz
 * @date 2024-02-03
 */
@Service
public class KnowledgeNoteServiceImpl implements IKnowledgeNoteService 
{
    @Autowired
    private KnowledgeNoteMapper knowledgeNoteMapper;
    
    @Autowired
    private KnowledgeNoteRepository knowledgeNoteRepository;

    /**
     * 查询小记
     * 
     * @param noteId 小记主键
     * @return 小记
     */
    @Override
    public KnowledgeNote selectKnowledgeNoteByNoteId(Long noteId)
    {
        return knowledgeNoteMapper.selectKnowledgeNoteByNoteId(noteId);
    }

    /**
     * 查询小记列表
     * 
     * @param knowledgeNote 小记
     * @return 小记
     */
    @Override
    public List<KnowledgeNote> selectKnowledgeNoteList(KnowledgeNote knowledgeNote)
    {
        return knowledgeNoteRepository.findAll();
    }

    /**
     * 新增小记
     * 
     * @param knowledgeNote 小记
     * @return 结果
     */
    @Override
    public KnowledgeNote insertKnowledgeNote(KnowledgeNote knowledgeNote)
    {
        if (StringUtils.isEmpty(knowledgeNote.getNoteId())) {
            knowledgeNote.setCreateInfo();
        } else {
            knowledgeNote.setUpdateInfo();
        }
        return knowledgeNoteRepository.save(knowledgeNote) == null ? null : knowledgeNote;
    }

    /**
     * 修改小记
     * 
     * @param knowledgeNote 小记
     * @return 结果
     */
    @Override
    public int updateKnowledgeNote(KnowledgeNote knowledgeNote)
    {
        return knowledgeNoteMapper.updateKnowledgeNote(knowledgeNote);
    }

    /**
     * 批量删除小记
     * 
     * @param noteIds 需要删除的小记主键
     * @return 结果
     */
    @Override
    public int deleteKnowledgeNoteByNoteIds(Long[] noteIds)
    {
        return knowledgeNoteMapper.deleteKnowledgeNoteByNoteIds(noteIds);
    }

    /**
     * 删除小记信息
     * 
     * @param noteId 小记主键
     * @return 结果
     */
    @Override
    public int deleteKnowledgeNoteByNoteId(Long noteId)
    {
        return knowledgeNoteMapper.deleteKnowledgeNoteByNoteId(noteId);
    }
}
